package org.come.action.petpaixu;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.PetOrderBtn;
import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;
import org.come.entity.RoleSummoning;
import org.come.until.ScrollUI;
import org.come.until.SrcollPanelUI;
import org.come.until.UserMessUntil;

import javax.swing.*;
import java.awt.*;
import java.awt.image.ImageObserver;
import java.util.Iterator;
import java.util.List;



public class PetpxJpanel extends JPanel
{
    private static PetpxJpanel petpxJpanel;
    private JScrollPane jScrollPane;
    private JList<String> listpet;
    private static DefaultListModel<String> listModel;
    private PetOrderBtn btntop;
    private PetOrderBtn btnbottom;
    private PetOrderBtn btntopset;
    private PetOrderBtn btnbottomset;
    private JLabel labOpen;
    private JLabel labLocking;
    private static int warNum;
    public static int idx;
    private FormsOnOffBtn offBtn;

    private ImageIcon iconD;


    public PetpxJpanel() throws Exception {

        if ("水墨UI".equals(MyIsif.getStyle())) {
            (PetpxJpanel.petpxJpanel = this).setPreferredSize(new Dimension(293, 409));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);
            (this.offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 1117)).setBounds(293 - 37, 10, 25, 25);
            this.add((Component) this.offBtn);
            PetpxJpanel.listModel = new DefaultListModel();
            (this.listpet = new JList<String>(PetpxJpanel.listModel) {
                {
                    this.setOpaque(false);
                }
            }).setSelectionBackground(new Color(33, 42, 52));
            this.listpet.setModel(PetpxJpanel.listModel);
            this.listpet.setSelectionMode(0);
            this.listpet.setCellRenderer(new MyRenderer());
            (this.jScrollPane = new JScrollPane((Component) this.listpet)).setVerticalScrollBarPolicy(22);
            this.jScrollPane.getViewport().setOpaque(false);
            this.jScrollPane.setOpaque(false);
            this.jScrollPane.setBorder(BorderFactory.createEmptyBorder());
            this.jScrollPane.setHorizontalScrollBarPolicy(31);
            this.jScrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
            this.jScrollPane.setBounds(51, 46, 194, 316);
            this.add((Component) this.jScrollPane);
            (this.labOpen = new JLabel()).setBounds(31, 261, 15, 15);
            this.add((Component) this.labOpen);
            (this.labLocking = new JLabel()).setBounds(31, 282, 15, 15);
            this.add((Component) this.labLocking);
            (this.btntop = new PetOrderBtn("skin/8100226/button/B42.png", 1, 0, this)).setBounds(258, 118, 17, 17);
            this.add((Component) this.btntop);
            (this.btnbottom = new PetOrderBtn("skin/8100226/button/B43.png", 1, 1, this)).setBounds(258, 147, 17, 17);
            this.add((Component) this.btnbottom);
            (this.btntopset = new PetOrderBtn("skin/8100226/button/19.png", 1, 2, "顶", this)).setBounds(258, 201, 18, 18);
            this.add((Component) this.btntopset);
            (this.btnbottomset = new PetOrderBtn("skin/8100226/button/19.png", 1, 3, "底", this)).setBounds(258, 230, 18, 18);
            this.add((Component) this.btnbottomset);
        }else{

            (PetpxJpanel.petpxJpanel = this).setPreferredSize(new Dimension(246, 307));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);

            (this.offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 125)).setBounds(293 - 37, 10, 25, 25);
            this.add((Component) this.offBtn);
            PetpxJpanel.listModel = new DefaultListModel();
            (this.listpet = new JList<String>(PetpxJpanel.listModel) {
                {
                    this.setOpaque(false);
                }
            }).setSelectionBackground(new Color(33, 42, 52));
            this.listpet.setModel(PetpxJpanel.listModel);
            this.listpet.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            this.listpet.setCellRenderer(new MyRenderer());
            (this.jScrollPane = new JScrollPane((Component) this.listpet)).setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            this.jScrollPane.getViewport().setOpaque(false);
            this.jScrollPane.setOpaque(false);
            this.jScrollPane.setBorder(BorderFactory.createEmptyBorder());
            this.jScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            this.jScrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
            this.jScrollPane.setBounds(40, 55, 194, 316);
            this.add((Component) this.jScrollPane);
            (this.labOpen = new JLabel()).setBounds(31, 261, 15, 15);
            this.add((Component) this.labOpen);
            (this.labLocking = new JLabel()).setBounds(31, 282, 15, 15);
            this.add((Component) this.labLocking);
            (this.btntop = new PetOrderBtn("inkImg/hongmu/1/24.png", 1, 0, this)).setBounds(205, 118-50, 17, 17);
            this.add((Component) this.btntop);
            (this.btnbottom = new PetOrderBtn("inkImg/hongmu/1/25.png", 1, 1, this)).setBounds(205, 147-50, 17, 17);
            this.add((Component) this.btnbottom);
            (this.btntopset = new PetOrderBtn("inkImg/hongmu/1/a3.png", 1, 2, "顶", this)).setBounds(205, 201-50, 18, 18);
            this.add((Component) this.btntopset);
            (this.btnbottomset = new PetOrderBtn("inkImg/hongmu/1/a3.png", 1, 3, "底", this)).setBounds(205, 230-50, 18, 18);
            this.add((Component) this.btnbottomset);
        }
    }

    public static void showStar() {
        if (RoleData.getRoleData().getLoginResult().getSummoning_id() != null) {
            PetpxJpanel.listModel.removeAllElements();
            int i = 0;
            while (i < UserMessUntil.getPetListTable().size()) {
                PetpxJpanel.listModel.add(i, ((RoleSummoning)UserMessUntil.getPetListTable().get(i)).getSummoningname());
                ++i;
            }
        }
        else {
            PetpxJpanel.listModel.removeAllElements();
            int i = 0;
            while (i < UserMessUntil.getPetListTable().size()) {
                PetpxJpanel.listModel.add(i, ((RoleSummoning)UserMessUntil.getPetListTable().get(i)).getSummoningname());
                ++i;
            }
        }
    }

    private ImageIcon iconS = new ImageIcon( "inkImg/newbackground/B332.png");
    private ImageIcon iconH = new ImageIcon("inkImg/hongmu/1/ss617.png");

    @Override
    protected void paintComponent(final Graphics g) {
        super.paintComponent(g);

        if ("水墨UI".equals(MyIsif.getStyle())) {
            this.jScrollPane.setBounds(51, 46, 194, 316);
            g.drawImage(this.iconS.getImage(), 0, 0, 293, 409, (ImageObserver) this);
        }else{
            this.jScrollPane.setBounds(35, 58, 160, 195);
            g.drawImage(this.iconH.getImage(), 0, 0, 246, 307, (ImageObserver)this);
        }

    }


    public void init(final List<String> list) {
        PetpxJpanel.listModel.clear();
        final Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            final String s = (String)iterator.next();
            PetpxJpanel.listModel.addElement(s);
        }
    }

    public DefaultListModel<String> getListModel() {
        return PetpxJpanel.listModel;
    }

    public void setListModel(final DefaultListModel<String> listModel) {
        PetpxJpanel.listModel = listModel;
    }

    public JList<String> getListpet() {
        return this.listpet;
    }

    public void setListpet(final JList<String> listpet) {
        this.listpet = listpet;
    }

    public JScrollPane getjScrollPane() {
        return this.jScrollPane;
    }

    public void setjScrollPane(final JScrollPane jScrollPane) {
        this.jScrollPane = jScrollPane;
    }

    public PetOrderBtn getBtntop() {
        return this.btntop;
    }

    public void setBtntop(final PetOrderBtn btntop) {
        this.btntop = btntop;
    }

    public PetOrderBtn getBtnbottom() {
        return this.btnbottom;
    }

    public void setBtnbottom(final PetOrderBtn btnbottom) {
        this.btnbottom = btnbottom;
    }

    public PetOrderBtn getBtntopset() {
        return this.btntopset;
    }

    public void setBtntopset(final PetOrderBtn btntopset) {
        this.btntopset = btntopset;
    }

    public PetOrderBtn getBtnbottomset() {
        return this.btnbottomset;
    }

    public void setBtnbottomset(final PetOrderBtn btnbottomset) {
        this.btnbottomset = btnbottomset;
    }

    public JLabel getLabOpen() {
        return this.labOpen;
    }

    public void setLabOpen(final JLabel labOpen) {
        this.labOpen = labOpen;
    }

    public JLabel getLabLocking() {
        return this.labLocking;
    }

    public void setLabLocking(final JLabel labLocking) {
        this.labLocking = labLocking;
    }

    public static int getWarNum() {
        return PetpxJpanel.warNum;
    }

    public static void setWarNum(final int warNum) {
        PetpxJpanel.warNum = warNum;
    }

    public static int getIdx() {
        return PetpxJpanel.idx;
    }

    public static void setIdx(final int idx) {
        PetpxJpanel.idx = idx;
    }

    public FormsOnOffBtn getOffBtn() {
        return this.offBtn;
    }

    public void setOffBtn(final FormsOnOffBtn offBtn) {
        this.offBtn = offBtn;
    }

    public ImageIcon getIconS() {
        return this.iconS;
    }

    public void setIconS(final ImageIcon iconS) {
        this.iconS = iconS;
    }

    public ImageIcon getIconH() {
        return this.iconH;
    }

    public void setIconH(final ImageIcon iconH) {
        this.iconH = iconH;
    }

    public ImageIcon getIconD() {
        return this.iconD;
    }

    public void setIconD(final ImageIcon iconD) {
        this.iconD = iconD;
    }

    public static PetpxJpanel getPetpxJpanel() {
        return PetpxJpanel.petpxJpanel;
    }

    public static void setPetpxJpanel(final PetpxJpanel petpxJpanel) {
        PetpxJpanel.petpxJpanel = petpxJpanel;
    }


    public void init(List<String> list,int index) {
        listModel.clear();
        for (int i = 0; i < list.size(); i++) {
            listModel.addElement(list.get(i));
        }
        if (index != -1) {
            listpet.setSelectedIndex(index);
        }
    }
    static {
        warNum = -1;
        idx = -1;
    }
}
